let fs = require('fs');
let url = require('url');
let path = require('path');
let http = require('http');

let workPath = path.resolve('.');

let server = http.createServer((req, res) => {

    res.write('<head><meta charset="utf8"/ ></head>');
    let reqPath = req.url;
    console.log(reqPath);
     if (req.url !== '/favicon.ico') {
        let fullPath = path.join(workPath, reqPath);
        console.log(fullPath);
        let item = fs.readdirSync(fullPath);
        console.log(item);
        item.forEach(x => {
            if (x === 'index.html') {
                let file = path.join(fullPath, x)
                console.log(file);

                fs.createReadStream(file).pipe(res);
            }
        })
    } else { console.log('糟糕出现小图标了'); }
    // // res.end();
});

server.listen(3100);
console.log('Server running at http://127.0.0.1:3100/');